﻿namespace KinonekoSoftware.CodariaDB.Documents.Theories.Elements
{
    public class TheoryEngine_Element : TheoryEngine<Element>
    {
        private const string Object_Theory_Elements = "KinonekoSoftware.CodariaDB.Documents.Theories.Elements.TheoryOfElements";

        public void Add(Element element)
        {
            if (element is null)
            {
                return;
            }

            //
            //
            ((IGlossaryOperation)element).Add(this);

            //
            //
            InsideDB.Insert(element);
            InternalCollection.Add(element);
            Modified();
        }

        public void Update(Element element)
        {
            if (element is null)
            {
                return;
            }

            //
            //
            ((IGlossaryOperation)element).Update(this);

            //
            //
            InsideDB.Update(element);
            Modified();
        }
        
        
        public void Clear()
        {
            //
            //
            foreach (var element in InternalCollection)
            {
                //
                //
                ((IGlossaryOperation)element).Remove(this);
                
                //
                //
                InsideDB.Delete(element.Id);
                
                //
                //
                InternalCollection.Remove(element);
            }
            
            
            Modified();
        }

        public void Remove(Element element)
        {
            if (element is null)
            {
                return;
            }

            //
            //
            ((IGlossaryOperation)element).Remove(this);

            //
            //
            InsideDB.Delete(element.Id);
            InternalCollection.Remove(element);
            Modified();
        }


        protected override void OnInitialize()
        {

#if DEBUG
            Add(new Element { Id = ID.Get(), Name = "风元素", Foreground = "#FFFFFF", Background = "#12AA9C", Image = "风", Icon = "风2" });
            Add(new Element { Id = ID.Get(), Name = "火属性", Foreground = "#FFFFFF", Background = "#C12C1F", Image = "火", Icon = "火2" });
            Add(new Element { Id = ID.Get(), Name = "水元素", Foreground = "#FFFFFF", Background = "#0eb0c9", Image = "水", Icon = "水2" });
            Add(new Element { Id = ID.Get(), Name = "岩元素", Foreground = "#FFFFFF", Background = "#bec936", Image = "岩", Icon = "岩2" });
            Add(new Element { Id = ID.Get(), Name = "雷元素", Foreground = "#FFFFFF", Background = "#6A00FF", Image = "雷", Icon = "雷2" });
            Add(new Element { Id = ID.Get(), Name = "暗元素", Foreground = "#FFFFFF", Background = "#2E317C", Image = "暗", Icon = "暗2" });
            Add(new Element { Id = ID.Get(), Name = "光元素", Foreground = "#212329", Background = "#fc8c23", Image = "光", Icon = "光2" });

#else
            Add(new Element { Id = ID.Get(), Name = "风元素", Foreground = "#FFFFFF", Background = "#12AA9C" });
            Add(new Element { Id = ID.Get(), Name = "火属性", Foreground = "#FFFFFF", Background = "#C12C1F" });
            Add(new Element { Id = ID.Get(), Name = "水元素", Foreground = "#FFFFFF", Background = "#0eb0c9" });
            Add(new Element { Id = ID.Get(), Name = "岩元素", Foreground = "#FFFFFF", Background = "#bec936" });
            Add(new Element { Id = ID.Get(), Name = "雷元素", Foreground = "#FFFFFF", Background = "#6A00FF" });
            Add(new Element { Id = ID.Get(), Name = "暗元素", Foreground = "#FFFFFF", Background = "#2E317C" });
            Add(new Element { Id = ID.Get(), Name = "光元素", Foreground = "#212329", Background = "#fc8c23" });
#endif
        }

        public override string EngineID            => EngineNames.Theory_Element;
        public override string GetCollectionName() => CollectionNames.Theory_ElementDB;
    }
}